<template>
	<div>
		<div class="userform">
			<el-form label-width="150px" :model="userform">
				<el-form-item label="用户名：">
					<el-input v-model="userform.username" :disabled="true"></el-input>
				</el-form-item>
				<!-- <el-form-item label="密码：">
					<el-input v-model="userform.password"></el-input>
				</el-form-item> -->
				<el-form-item label="姓名：">
					<el-input v-model="userform.realname" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item label="学号：">
					<el-input
						v-model="userform.student_num"
						oninput="value=value.replace(/[^\d]/g, '')"
						maxlength="12"
						:disabled="true"
					></el-input>
				</el-form-item>
				<el-form-item label="用户权限：">
					<el-radio-group v-model="userform.role">
						<el-radio label="sadmin">超级管理员</el-radio>
						<el-radio label="admin">管理员</el-radio>
						<el-radio label="user">普通用户</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">保存</el-button>
					<el-button @click="fanhui">返回</el-button>
				</el-form-item>
			</el-form>
		</div>
	</div>
</template>

<script>
import baseUrl from "../../utils/baseURL";
	export default {
		data() {
			return {
				userform: {
          // id:"",
					username: "",
					// password: "",
					realname: "",
					student_num: "",
					role: "",
				},
			};
		},
		methods: {
			onSubmit() {
        const _this = this;
				axios
					.post(baseUrl+"/sys/updateSysUser", {
						username: _this.userform.username,
						role: _this.userform.role,
					})
					.then(function (resp) {
						console.log(resp);
						if (resp.data.code == 200) {
							_this.$message({
								message: "当前用户权限修改成功，即将跳转...",
								type: "success",
							});
              setTimeout(() => {
								//需要延迟的代码 :3秒后延迟跳转到首页，可以加提示什么的
								_this.$router.go(-1);
								//延迟时间：3秒
							}, 2000);
						}
					});
			},
			fanhui() {
				this.$router.go(-1);
			},
		},
		created() {
			let nowUser = JSON.parse(window.localStorage.getItem("nowUser"));
			console.log(nowUser);
			// this.userform.id = nowUser.id;
			this.userform.username = nowUser.username;
			// this.userform.password = nowUser.password;
			this.userform.realname = nowUser.realname;
			this.userform.student_num = nowUser.student_num;
			this.userform.role = nowUser.role;
		},
	};
</script>

<style>
	.userform {
		padding-top: 80px;
		max-width: 90%;
	}
	.el-form {
		max-width: 500px;
	}
</style>